<template>
  <div class="app-container">
    <el-form ref="ruleForm" :model="formData" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="灌溉时间" prop="created_at">
        <el-date-picker
          v-model="formData.created_at"
          type="datetime"
          placeholder="选择日期时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          align="center"
        />
      </el-form-item>
      <el-form-item label="灌溉量" prop="amount_raw">
        <el-input v-model="formData.amount_raw" type="number" placeholder="灌溉量(m³)">
          <template slot="append">m³</template>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit('ruleForm')">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  props: {
    formData: {
      type: Object,
      default() {
        return {
          emails: []
        }
      }
    }
  },
  data() {
    return {
      rules: {
        created_at: [
          { required: true, message: '请选择灌溉时间', trigger: 'blur' }
        ],
        amount_raw: [
          { required: true, message: '请输入灌溉量', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('irrigationSubmit', this.formData)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
